<template>
    <div class='container'>
      <el-dialog
    title="修改目录"
    :visible.sync="dialogVisible2"
    width="30%"
    :before-close="handleClose">

     <div style="display: flex;align-items: center;flex-direction: column;">

     <div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="所属学科" prop="subjectID">
      <el-select v-model="ruleForm.subjectID" style="width: 300px;" placeholder="请选择">
      <el-option
       v-for="(item,index) in arr"
        :key="index"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>

        </el-form-item>
    <el-form-item label="目录名称" prop="directoryName">
      <el-input v-model="ruleForm.directoryName" style="width: 300px;"></el-input>
    </el-form-item>
    </el-form>
     </div>
     </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleAdd">确 定</el-button>
    </span>
  </el-dialog>
    </div>
  </template>

<script>
import { addList, update } from '@/api/hmmm/directorys'
export default {
  props: {
    dialogVisible2: {
      type: Boolean
    }
  },
  data () {
    return {

      ruleForm: {
        directoryName: '',
        subjectID: '',
        id: ''
      },
      rules: {
        directoryName: [
          { required: true, message: '请输入目录名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ]
      },
      arr: []
    }
  },
  created () {
    this.addList()
  },
  methods: {
    handleClose () {
      this.$emit('update:dialogVisible2', false)
    },
    async addList () {
      const data = await addList()
      this.arr = data.data
    },
    // 修改目录 确定按钮
    async handleAdd () {
      this.$emit('update:dialogVisible2', false)
      await update(this.ruleForm)
      this.$parent.getlist()
      console.log(this.$parent.form)
      this.ruleForm.directoryName = ''
      this.ruleForm.subjectID = ''
    }
  }
}
</script>

  <style scoped lang='less'></style>
